package com.cleaningcloud.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cleaningcloud.erp.domain.excelExport.CustomerExport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.erp.api.domain.ErpCustomer;
import com.cleaningcloud.erp.service.IErpCustomerService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 客户管理Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-02
 */
@RestController
@RequestMapping("/ErpCustomer")
public class ErpCustomerController extends BaseController
{
    @Autowired
    private IErpCustomerService erpCustomerService;

    /**
     * 查询客户管理列表
     */
    @RequiresPermissions("erp:ErpCustomer:list")
    @GetMapping("/list")
    public TableDataInfo list(ErpCustomer erpCustomer)
    {
        startPage();
        List<ErpCustomer> list = erpCustomerService.selectErpCustomerList(erpCustomer);
        return getDataTable(list);
    }

    @GetMapping("/getList")
    public AjaxResult list()
    {
        return success(erpCustomerService.getErpCustomerList());
    }

    /**
     * 导出客户管理列表
     */
    @RequiresPermissions("erp:ErpCustomer:export")
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerExport customerExport)
    {
        List<CustomerExport> list = erpCustomerService.exportErpCustomerList(customerExport);
        ExcelUtil<CustomerExport> util = new ExcelUtil<CustomerExport>(CustomerExport.class);
        util.exportExcel(response, list, "客户管理数据");
    }

    /**
     * 获取客户管理详细信息
     */
    @RequiresPermissions("erp:ErpCustomer:query")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return success(erpCustomerService.selectErpCustomerByCustomerId(customerId));
    }

    /**
     * 新增客户管理
     */
    @RequiresPermissions("erp:ErpCustomer:add")
    @Log(title = "客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpCustomer erpCustomer)
    {
        return toAjax(erpCustomerService.insertErpCustomer(erpCustomer));
    }

    /**
     * 修改客户管理
     */
    @RequiresPermissions("erp:ErpCustomer:edit")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpCustomer erpCustomer)
    {
        return toAjax(erpCustomerService.updateErpCustomer(erpCustomer));
    }

    /**
     * 删除客户管理
     */
    @RequiresPermissions("erp:ErpCustomer:remove")
    @Log(title = "客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(erpCustomerService.deleteErpCustomerByCustomerIds(customerIds));
    }

    /**
     * @Author Shaw
     * @Description 审核客户
     * @date: 2025-04-02 16:21
     * @param: //TODO
     */
    @RequiresPermissions("cld:ErpCustomer:audit")
    @Log(title = "客户管理", businessType = BusinessType.AUDIT)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody ErpCustomer erpCustomer)
    {
        return toAjax(erpCustomerService.auditErpCustomer(erpCustomer));
    }
}
